# -*- coding:utf-8 -*-
import os
import codecs

"""
脚本作用：windows下HTML文件中字符批量替换
    所需参数
    路径，替换的字符
"""

replace_target = ""
def replaceHTML(path):
    filelist=os.listdir(path)
    #该文件夹下所有的文件（包括文件夹）
    
    for files in filelist:      #遍历所有文件
        olddir = os.path.join(path, files)
        if not os.path.isdir(olddir) and ".html" in os.path.splitext(files)[1]:
            fp = open(olddir, 'r', encoding="utf-8")
            pstr = fp.read()
            fp.close()
            if replace_target in pstr:
                pstr = pstr.replace(replace_target, "")
                fs = open(olddir, 'w', encoding="utf-8")
                fs.write(pstr)
                fs.close()
                print(os.path.splitext(files)[0], "已清除...")


if __name__ == '__main__':
    path = input('please input path:')
    replace_target = input('please input need replace char:')
    #print(path, replace_target)   
    replaceHTML(path)
